package com.avecsys.quotemanager.mbeans.buyer;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.avecsys.quotemanager.constants.BusinessCodes;
import com.avecsys.quotemanager.exception.BusinessException;
import com.avecsys.quotemanager.mbeans.core.BaseMBean;
import com.avecsys.quotemanager.pojos.BuyerUsersPojo;
import com.avecsys.quotemanager.pojos.QuoteTransactionPojo;
import com.avecsys.quotemanager.pojos.UserMasterPojo;
import com.avecsys.quotemanager.service.supplier.QuoteTransactionService;
import com.avecsys.quotemanager.utils.MessageBoardUtil;

/**
 * @author Sam Sundar K
 */
public class QuoteTransactionListMBean extends BaseMBean implements Serializable
{
	private final Log log = LogFactory.getLog(QuoteTransactionListMBean.class);

	private QuoteTransactionService quoteTransactionService;

	private List<QuoteTransactionPojo> quoteTransactionPojoList = new ArrayList<QuoteTransactionPojo>();

	/**
	 * @return the quoteTransactionPojoList
	 */
	public List<QuoteTransactionPojo> getQuoteTransactionPojoList()
	{
		return quoteTransactionPojoList;
	}

	/**
	 * @return the quoteTransactionService
	 */
	public QuoteTransactionService getQuoteTransactionService()
	{
		return quoteTransactionService;
	}

	public void loadAllBuyerAcceptedQuotes()
	{
		UserMasterPojo userMasterPojo = getSignedInUser();
		if (userMasterPojo != null)
		{
			for (BuyerUsersPojo buyerUsersPojo : userMasterPojo.getBuyerUsersPojo())
			{
				try
				{
					List<String> transactionStatusList = new ArrayList<String>();
					transactionStatusList.add(BusinessCodes.QUOTE_EVENT_TRANSACTION_STATUS_BUYER_ACCEPT);
					transactionStatusList.add(BusinessCodes.QUOTE_EVENT_TRANSACTION_STATUS_BUYER_IGNORE);
					setQuoteTransactionPojoList(quoteTransactionService.getAllQuoteTransactionsForBuyer(
							buyerUsersPojo.getBuyerMasterPojo(),
								transactionStatusList));
				}
				catch (BusinessException e)
				{
					log.error(e);
					MessageBoardUtil.publishException(e);
				}
			}
		}
	}

	/**
	 * @param quoteTransactionPojoList the quoteTransactionPojoList to set
	 */
	public void setQuoteTransactionPojoList(List<QuoteTransactionPojo> quoteTransactionPojoList)
	{
		this.quoteTransactionPojoList = quoteTransactionPojoList;
	}

	/**
	 * @param quoteTransactionService the quoteTransactionService to set
	 */
	public void setQuoteTransactionService(QuoteTransactionService quoteTransactionService)
	{
		this.quoteTransactionService = quoteTransactionService;
	}

}
